package com.ruoyi.service.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.service.domain.HealthService;
import com.ruoyi.service.service.IHealthServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 健康服务Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/service/service")
public class HealthServiceController extends BaseController
{
    @Autowired
    private IHealthServiceService healthServiceService;

    /**
     * 查询健康服务列表
     */
    @PreAuthorize("@ss.hasPermi('service:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthService healthService)
    {
        startPage();
        List<HealthService> list = healthServiceService.selectHealthServiceList(healthService);
        return getDataTable(list);
    }

    /**
     * 导出健康服务列表
     */
    @PreAuthorize("@ss.hasPermi('service:service:export')")
    @Log(title = "健康服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthService healthService)
    {
        List<HealthService> list = healthServiceService.selectHealthServiceList(healthService);
        ExcelUtil<HealthService> util = new ExcelUtil<HealthService>(HealthService.class);
        util.exportExcel(response, list, "健康服务数据");
    }

    /**
     * 获取健康服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:service:query')")
    @GetMapping(value = "/{serviceId}")
    public AjaxResult getInfo(@PathVariable("serviceId") Long serviceId)
    {
        return success(healthServiceService.selectHealthServiceByServiceId(serviceId));
    }

    /**
     * 新增健康服务
     */
    @PreAuthorize("@ss.hasPermi('service:service:add')")
    @Log(title = "健康服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthService healthService)
    {
        return toAjax(healthServiceService.insertHealthService(healthService));
    }

    /**
     * 修改健康服务
     */
    @PreAuthorize("@ss.hasPermi('service:service:edit')")
    @Log(title = "健康服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthService healthService)
    {
        return toAjax(healthServiceService.updateHealthService(healthService));
    }

    /**
     * 删除健康服务
     */
    @PreAuthorize("@ss.hasPermi('service:service:remove')")
    @Log(title = "健康服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serviceIds}")
    public AjaxResult remove(@PathVariable Long[] serviceIds)
    {
        return toAjax(healthServiceService.deleteHealthServiceByServiceIds(serviceIds));
    }
}
